home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11437 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.4 KB  |  72 lines

  1. Path: uuneo.neosoft.com!usenet
  2. From: Wmatthew@lan-aces.com (W. Matthews)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: template with unknown classes!
  5. Date: 14 Mar 1996 16:19:04 GMT
  6. Organization: LAN-ACES, Inc.
  7. Message-ID: <4i9gto$dtu@uuneo.neosoft.com>
  8. References: <3146F7D0.791D@nada.kth.se>
  9. NNTP-Posting-Host: 198.65.178.8
  10. X-Newsreader: WinVN 0.92.5
  11.  
  12. In article <3146F7D0.791D@nada.kth.se>, Andreas SwΣrdh <da1-asw@nada.kth.se> says:
  13. >
  14. >My real problem is that I havn't found any good referens about
  15. >advance templates.
  16. >
  17. >So my question is: If you got an exemple like the one below
  18. >is there an solution to find?
  19. >
  20. >class listhandler
  21. >{
  22. >  private:
  23. >    node *head;     // my baseclass pointer. could be a Void* too, just
  24. >  public:           // to make it even more complicated.
  25. >    listhandler(){head = null;};
  26. >    void new_object();   // here is the functions definition.  
  27. >    ...
  28. >    ...
  29. >}
  30. >// I Would like to create an listhandler that works on everything. That 
  31. >can
  32. >// take an unknown  class (of course it must be a defined class) and 
  33. >create it
  34. >// with NEW. I thought it would be easy to do with templates but haven't 
  35. >had
  36. >// any success yet. The problem is that I don't want the hole class to 
  37. >be a
  38. >// template, just THIS funktion. Is there a solution with templetes or 
  39. >do 
  40. >// you have to use friend in some sort of way? Maybe use of 
  41. >dummy-class-pointer
  42. >// just to get the right class type?! Would be most greatful for fast 
  43. >replies.
  44. >
  45. >// The possible function?!
  46. >
  47. >template<class object>void new_object()   // or something like that!
  48. >{
  49. >  if(!head)
  50. >    head = new object;  // where object doesn't have to be known.
  51. >  ...                   // And the constuctor of object initializes it!
  52. >  ...
  53. >}
  54. >
  55. >// It shall be intresting to see what kind of solutions you can dig out
  56. >// of your closet!
  57. >//
  58. >// If you wanna mail me personaly: MAILTO:da1_asw@nada.kth.se
  59. >//
  60. >// Bye for know!!
  61. how about a friend function?  Another post on comp.lang.c++ was asking
  62. about templating a single function....
  63. ______________________________________________
  64. |Wyatt Matthews:       Tech Support Department |
  65. |WMATTHEW@LAN-ACES.COM        -Internet-       |
  66. |WMATTHEW.MHS@LAN-ACES          -MHS-          |
  67. |LAN-ACES Tech Support      (713)890-9786      |
  68. |LAN-ACES BBS               (713)890-9790      |
  69. |LAN-ACES Fax               (713)890-9731      |
  70. |LAN-ACES Sales             (713)890-9787      |
  71. ______________________________________________
  72.